﻿
# soreted
# sorted(iterable, cmp=None, key=None, reverse=False) --> new sorted list

print "sorted([36,5,12,9,21]) =",sorted([36,5,12,9,21])
print "sorted([36,5,12,9,21],reverse=True) =",sorted([36,5,12,9,21],reverse=True)

def reversed_cmp(x,y):
	if x>y :
		return -1
	if x<y :
		return 1
	return 0

print "sorted([36,5,12,9,21],reversed_cmp) =",sorted([36,5,12,9,21],reversed_cmp)

# 默认情况下，对字符串排序，是按照ASCII的大小比较的，由于'Z' < 'a'，结果，大写字母Z会排在小写字母a的前面。
print "sorted(['bob','about','Zoo','Credit']) =",sorted(['bob','about','Zoo','Credit'])

def cmp_ignore_case(s1,s2):
	u1=s1.upper()
	u2=s2.upper()
	if u1<u2:
		return -1
	if u1>u2:
		return 1
	return 0

print "sorted(['bob','about','Zoo','Credit'],cmp_ignore_case) =",sorted(['bob','about','Zoo','Credit'],cmp_ignore_case)